import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:glorysoft_mobile_plugin/tool/extensions/extension.dart';
import 'package:glorysoft_mobile_plugin/tool/global/global_method.dart';
import 'package:glorysoft_mobile_plugin/tool/widget/custom_text/custom_text.dart';
import 'package:quick_code_platform/constant/constant.dart';
import 'setting_controller.dart';
import 'package:getwidget/getwidget.dart';

class SettingPage extends StatelessWidget{
  final controller = Get.put(SettingController());
  final OutlineInputBorder _outlineInputBorder = OutlineInputBorder(
    gapPadding: 0,
    borderRadius: BorderRadius.circular(16.0),
    borderSide: BorderSide(
      color:middle_white.toColor(),
    ),
  );
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: GFAppBar(
          backgroundColor: theme_blue.toColor(),
          centerTitle: true,
          elevation: 0.5,
          leading: Visibility(
            visible: true,
            child: GFIconButton(
                icon: Image.asset("assets/images/white_back_normal.png"),
                onPressed: () {
                  Get.back();
                },
                type: GFButtonType.transparent),
          ),
          title: Text(
             "设置",
            style: TextStyle(fontSize: 16, color:  middle_white.toColor() ),
          ),
          actions: [
            UnconstrainedBox(
              child: SizedBox(
                width: 50,
                child: GFButton(
                  size: 24,
                  onPressed: () {
                    controller.saveAllConfig();
                  },
                  shape: GFButtonShape.pills,
                  type: GFButtonType.outline,
                  color: middle_white.toColor(),
                  child: Text( "保存",
                      style: TextStyle(
                          fontSize: 12, color: middle_white.toColor())),
                ).marginOnly(right: 8),
              ),
            ),
          ],
        ),
        body: GetBuilder<SettingController>(builder: (controller) {
          return SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                CustomText('接口地址', fontSize: 16,color: theme_blue.toColor()),
                TextField(
                  decoration: InputDecoration(
                    //isCollapsed:true,
                      hintText:  "请输入接口地址",
                      border: _outlineInputBorder,
                      fillColor: light_gray.toColor(),
                      //背景颜色，必须结合filled: true,才有效
                      filled: true,
                      //重点，必须设置为true，fillColor才有效
                      focusedBorder: _outlineInputBorder,
                      enabledBorder: _outlineInputBorder,
                      disabledBorder: _outlineInputBorder,
                      focusedErrorBorder: _outlineInputBorder,
                      errorBorder: _outlineInputBorder,
                      contentPadding: const EdgeInsets.only(
                          left: 8, top: 8, bottom: 8, right: 0),
                      //文本框的尾部图标
                      suffixIcon: (controller.address?.text??"").isNotEmpty
                          ? IconButton(
                        //如果文本长度不为空则显示清除按钮
                          onPressed: () {
                            controller.itfId?.clear();
                          },
                          icon: const Icon(
                            Icons.cancel,
                            color: Colors.grey,
                            size: 16,
                          ))
                          : null),
                  controller: controller.itfId,
                  onChanged: (value) {
                    controller.saveInterFaceConfig();
                  },
                ).marginOnly(top: 8),
                const SizedBox(height: 12),
                CustomText('文件地址', fontSize: 16,color: theme_blue.toColor()),
                TextField(
                  decoration: InputDecoration(
                    //isCollapsed:true,
                      hintText:  "请输入文件地址",
                      border: _outlineInputBorder,
                      fillColor: light_gray.toColor(),
                      //背景颜色，必须结合filled: true,才有效
                      filled: true,
                      //重点，必须设置为true，fillColor才有效
                      focusedBorder: _outlineInputBorder,
                      enabledBorder: _outlineInputBorder,
                      disabledBorder: _outlineInputBorder,
                      focusedErrorBorder: _outlineInputBorder,
                      errorBorder: _outlineInputBorder,
                      contentPadding: EdgeInsets.only(
                          left: 8, top: 8, bottom: 8, right: 0),
                      //文本框的尾部图标
                      suffixIcon: (controller.address?.text??"").isNotEmpty
                          ? IconButton(
                        //如果文本长度不为空则显示清除按钮
                          onPressed: () {
                            controller.address?.clear();
                          },
                          icon: Icon(
                            Icons.cancel,
                            color: Colors.grey,
                            size: 16,
                          ))
                          : null),
                  controller: controller.address,
                  onChanged: (value) {
                    controller.savePageConfig();
                  },
                ).marginOnly(top: 8),
                // Row(
                //   children: [
                //     Container(
                //       width: 120,
                //       child: DropdownSearch<Map<dynamic, dynamic>>(
                //         maxHeight:controller.mShowList.length<4? (56*controller.mShowList.length).toDouble():null,
                //         validator: (v) => v == null ? "required field" : null,
                //         dropdownSearchTextAlignVertical: TextAlignVertical.center,
                //         dropdownSearchDecoration: InputDecoration(
                //           contentPadding: const EdgeInsets.fromLTRB(12, 0, -12, 0),
                //           fillColor: Colors.grey[200],
                //           //背景颜色，必须结合filled: true,才有效
                //           filled: true,
                //           focusedBorder: _outlineInputBorder,
                //           enabledBorder: _outlineInputBorder,
                //           disabledBorder: _outlineInputBorder,
                //           focusedErrorBorder: _outlineInputBorder,
                //           errorBorder: _outlineInputBorder,
                //         ),
                //         mode: Mode.MENU,
                //         showSearchBox:  false,
                //         items: controller.mShowList,
                //         showSelectedItems: true,
                //         selectedItem: controller.selectPageAddress,
                //         compareFn: (i, s) => i?[controller.value] == (s?[controller.value]),
                //         popupItemBuilder: (context, element, isSelected) {
                //           return ListTile(
                //               title: Text(
                //                 element[controller.label],
                //                 style: TextStyle(color: text_black.toColor(), fontSize: 14),
                //               ));
                //         },
                //         dropdownBuilder: (context, element) {
                //           return TextField(
                //             enabled: false,
                //             decoration: InputDecoration(
                //                 labelText: element?[controller.label],
                //                 isCollapsed: true,
                //                 hintStyle: TextStyle(fontSize: 14, color: text_gray.toColor()),
                //                 labelStyle:
                //                 TextStyle(fontSize: 14, color: text_black.toColor()),
                //                 border: InputBorder.none),
                //           );
                //         },
                //         itemAsString: (element) {
                //           return element?[controller.label].toString() ?? '';
                //         },
                //       ),
                //     ),
                //
                //   ],
                // ),
                SizedBox(height: 12),
                Row(
                  children: [
                    CustomText('文件目录', fontSize: 16,color: theme_blue.toColor()),

                    CustomText('示例：/File/App', fontSize: 14,color:text_black.toColor()).marginOnly(left: 8),
                  ],
                ),
                TextField(
                  decoration: InputDecoration(
                    //isCollapsed:true,
                      hintText:  "请输入文件目录",
                      border: _outlineInputBorder,
                      fillColor: light_gray.toColor(),
                      //背景颜色，必须结合filled: true,才有效
                      filled: true,
                      //重点，必须设置为true，fillColor才有效
                      focusedBorder: _outlineInputBorder,
                      enabledBorder: _outlineInputBorder,
                      disabledBorder: _outlineInputBorder,
                      focusedErrorBorder: _outlineInputBorder,
                      errorBorder: _outlineInputBorder,
                      contentPadding: EdgeInsets.only(
                          left: 8, top: 8, bottom: 8, right: 0),
                      //文本框的尾部图标
                      suffixIcon: (controller.address?.text??"").isNotEmpty
                          ? IconButton(
                        //如果文本长度不为空则显示清除按钮
                          onPressed: () {
                            controller.filePath?.clear();
                          },
                          icon: Icon(
                            Icons.cancel,
                            color: Colors.grey,
                            size: 16,
                          ))
                          : null),
                  controller: controller.filePath,
                  onChanged: (value) {
                    controller.saveInterFaceConfig();
                  },
                ).marginOnly(top: 8),
                SizedBox(height: 12),
                CustomText('超时时间（秒）', fontSize: 16,color: theme_blue.toColor()),
                TextField(
                  decoration: InputDecoration(
                      hintText: '请输入超时时间',
                      border: _outlineInputBorder,
                      fillColor: light_gray.toColor(),
                      //背景颜色，必须结合filled: true,才有效
                      filled: true,
                      //重点，必须设置为true，fillColor才有效
                      focusedBorder: _outlineInputBorder,
                      enabledBorder: _outlineInputBorder,
                      disabledBorder: _outlineInputBorder,
                      focusedErrorBorder: _outlineInputBorder,
                      errorBorder: _outlineInputBorder,
                      contentPadding: EdgeInsets.only(
                          left: 8, top: 8, bottom: 8, right: 0),
                      //文本框的尾部图标
                      suffixIcon: (controller.address?.text??"").isNotEmpty
                          ? IconButton(
                        //如果文本长度不为空则显示清除按钮
                          onPressed: () {
                            controller.timeout?.clear();
                          },
                          icon: Icon(
                            Icons.cancel,
                            color: Colors.grey,
                            size: 16,
                          ))
                          : null
                  ),
                  controller: controller.timeout,
                  keyboardType: TextInputType.number,
                  onChanged: (value) {
                    controller.saveTimeout();
                  },
                ).marginOnly(top: 8),
                // SizedBox(height: 12),
                // CustomText('入口表单ID', fontSize: 16,color: theme_blue.toColor()),
                // TextField(
                //   decoration: InputDecoration(
                //       hintText: '请输入入口表单ID',
                //       border: _outlineInputBorder,
                //       fillColor: light_gray.toColor(),
                //       //背景颜色，必须结合filled: true,才有效
                //       filled: true,
                //       //重点，必须设置为true，fillColor才有效
                //       focusedBorder: _outlineInputBorder,
                //       enabledBorder: _outlineInputBorder,
                //       disabledBorder: _outlineInputBorder,
                //       focusedErrorBorder: _outlineInputBorder,
                //       errorBorder: _outlineInputBorder,
                //       contentPadding: EdgeInsets.only(
                //           left: 8, top: 8, bottom: 8, right: 0),
                //       //文本框的尾部图标
                //       suffixIcon: (controller.address?.text??"").isNotEmpty
                //           ? IconButton(
                //         //如果文本长度不为空则显示清除按钮
                //           onPressed: () {
                //             controller.itfId?.clear();
                //           },
                //           icon: Icon(
                //             Icons.cancel,
                //             color: Colors.grey,
                //             size: 16,
                //           ))
                //           : null
                //   ),
                //   controller: controller.formId,
                //   onChanged: (value) {
                //     controller.saveFormId();
                //   },
                // ).marginOnly(top: 8),
                const SizedBox(height: 12),
                CustomText('设备ID', fontSize: 16,color: theme_blue.toColor()),
                TextField(
                  decoration: InputDecoration(
                      hintText: '请扫描或输入设备ID',
                      border: _outlineInputBorder,
                      fillColor: light_gray.toColor(),
                      //背景颜色，必须结合filled: true,才有效
                      filled: true,
                      //重点，必须设置为true，fillColor才有效
                      focusedBorder: _outlineInputBorder,
                      enabledBorder: _outlineInputBorder,
                      disabledBorder: _outlineInputBorder,
                      focusedErrorBorder: _outlineInputBorder,
                      errorBorder: _outlineInputBorder,
                      contentPadding: const EdgeInsets.only(
                          left: 8, top: 8, bottom: 8, right: 0),
                      //文本框的尾部图标
                      suffixIcon: (controller.address?.text??"").isNotEmpty
                          ? IconButton(
                        //如果文本长度不为空则显示清除按钮
                          onPressed: () {
                            controller.eqpId?.clear();
                          },
                          icon: const Icon(
                            Icons.cancel,
                            color: Colors.grey,
                            size: 16,
                          ))
                          : null
                  ),
                  controller: controller.eqpId,
                  keyboardType: TextInputType.number,
                  onChanged: (value) {
                    controller.saveEqpId();
                  },
                ).marginOnly(top: 8),
                const SizedBox(height: 12),
                Row(
                  children: [
                    Expanded(
                        child: CustomText('开启错误弹窗', fontSize: 16,color: theme_blue.toColor())
                    ),
                    Switch(value: isHttpFailingModusOrDialog, onChanged: (value) {
                      isHttpFailingModusOrDialog = value;
                      controller.saveIsFailingDialog(value);
                    })
                  ],
                ),
                SizedBox(height: 0),
                Row(
                  children: [
                    Expanded(
                        child: CustomText('检查更新', fontSize: 16,color: theme_blue.toColor())
                    ),
                    ElevatedButton(onPressed: (){
                      controller.saveUpdateApp(isUpdate: true);
                    }, child: Text('更新'))
                  ],
                )
              ],
            ),
          );
        }).paddingAll(12)
    );
  }
}
